#pragma once
#include "opencv2/myopencv.hpp"
#include "../CommonUsed/tmatrixdef.h"

//This line comes from http://www.ee.oulu.fi/~topiolli/cpplibs/files/LBP.h
#define compab_mask(val,shift) { code |= ((unsigned int)(*center - (val) - 1) & 0x80000000) >> (31-shift); }

class LBPExtractor
{
public:
	LBPExtractor(int overlapping, int nBlocksX, int nBlocksY);
	virtual ~LBPExtractor(void);
	
	int Extract(CvMat* pGaborImage, BYTE* pSubBuf);// assume that pGaborImage is CV_32F
	
	const static int nBinNum = 59;
private:
	void LBPTransform(CvMat* pGaborImage);
	void LBPHistogram(BYTE* pSubBuf);
	void Prepare(void);
	int GetUniformCount(int code, int maxBit);

	int m_overlapping;
	int m_nBlocksX;
	int m_nBlocksY;
	int m_nBlocksTotal;
	CvMat* m_pTmpImage;
	CvMat* m_pBorderImage;
	int* m_piPatternCodec;
	int* m_blockIDTable;
};
